package com.hao.cdk.common.web;


import lombok.Data;

/**
 * @author: 许自豪
 * @date: 2025-01-17 15:39:07
 * @description: 通用Rest
 */
@Data
public class BaseRest {
    public BaseRest() {
    }

    public WebResponse<Void> buildSuccessResponse() {
        WebResponse<Void> webResponse = new WebResponse();
        webResponse.setMessage("成功");
        webResponse.setStatusCode(ResponseCode.OK.getValue());
        return webResponse;
    }

    public <T> WebResponse<T> buildErrorResponse(String error) {
        WebResponse<T> webResponse = new WebResponse<>();
        webResponse.setMessage(error);
        webResponse.setStatusCode(ResponseCode.ERROR_UNKNOWN.getValue());
        return webResponse;
    }

    public <T> WebResponse<T> buildResponse(T data) {
        WebResponse<T> webResponse = new WebResponse<>();
        webResponse.setResult(data);
        webResponse.setMessage("成功");
        webResponse.setStatusCode(ResponseCode.OK.getValue());
        return webResponse;
    }

    public <T> WebResponse<T> buildResponse(String statusCode, String message) {
        WebResponse<T> webResponse = new WebResponse<T>();
        webResponse.setMessage(message);
        webResponse.setStatusCode(statusCode);
        return webResponse;
    }
}
